package kr.yoon.practice.serviceUI;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;

import kr.yoon.practice.db.common.ConnectionFactory;
import kr.yoon.practice.db.dao.DaoInterface;
import kr.yoon.practice.db.dao.DepartmentDAO;
import kr.yoon.practice.db.dto.Department;

public class TestMainFrame extends JFrame implements ActionListener {
	Toolkit kit = Toolkit.getDefaultToolkit();
	Dimension screenSize = kit.getScreenSize();
	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenuItem mntmDptDel;
	private JMenuItem mntmDptAdd;
	private JMenuItem mntmDptUp;
	private JMenuItem mntmDptSearch;
	private JMenuItem mntmDptList;
	private PanelJtable deptJtable;
	public PanelDepartmentUI pnDept = new PanelDepartmentUI();
	private ArrayList<Department> dblist;
	
	private JPanel panel_Center;
	private JMenuItem mntmEmpDel;
	private JMenuItem mntmEmpUp;
	private JMenuItem mntmEmpSearch;
	private JMenuItem mntmEmpList;
	private JMenuItem mntmEmpAdd;
	public PanelDepartmentUI pnDeptBody = new PanelDepartmentUI();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestMainFrame frame = new TestMainFrame();
					frame.setVisible(true);
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TestMainFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 555, 500);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setLocation(screenSize.width / 2 -350, screenSize.height / 2 - 350);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		setContentPane(contentPane);
		
		menuBar = new JMenuBar();
		contentPane.add(menuBar, BorderLayout.NORTH);
		
		panel_Center = new JPanel();
		
		JMenu mnDepartment = new JMenu("부서정보");
		menuBar.add(mnDepartment);
		
		mntmDptAdd = new JMenuItem("부서 추가");
		mntmDptAdd.addActionListener(this);
		mnDepartment.add(mntmDptAdd);
		
		mntmDptDel = new JMenuItem("부서 삭제");
		mntmDptDel.addActionListener(this);
		mnDepartment.add(mntmDptDel);
		
		mntmDptUp = new JMenuItem("부서 수정");
		mntmDptUp.addActionListener(this);
		mnDepartment.add(mntmDptUp);
		
		mntmDptSearch = new JMenuItem("부서 검색");
		mntmDptSearch.addActionListener(this);
		mnDepartment.add(mntmDptSearch);
		
		mntmDptList = new JMenuItem("부서 리스트");
		mntmDptList.addActionListener(this);
		mnDepartment.add(mntmDptList);
		

		//사원정보
		JMenu mnEmployee = new JMenu("사원정보");
		menuBar.add(mnEmployee);
		
		mntmEmpAdd = new JMenuItem("사원 추가");
		mnEmployee.add(mntmEmpAdd);
		
		mntmEmpDel = new JMenuItem("사원 삭제");
		mnEmployee.add(mntmEmpDel);
		
		mntmEmpUp = new JMenuItem("사원 수정");
		mnEmployee.add(mntmEmpUp);
		
		mntmEmpSearch = new JMenuItem("사원 검색");
		mnEmployee.add(mntmEmpSearch);
		
		mntmEmpList = new JMenuItem("사원 리스트");
		mnEmployee.add(mntmEmpList);
		
		panel_Center = new JPanel();
		contentPane.add(panel_Center, BorderLayout.CENTER);
		panel_Center.setLayout(new BorderLayout(0, 0));
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == mntmDptList) {
			actionPerformedMntmDptList(e);
		}if (e.getSource() == mntmDptSearch) {
			actionPerformedMntmSearch(e);
		}if (e.getSource() == mntmDptUp) {
			actionPerformedMntmDptUp(e);
		}if (e.getSource() == mntmDptDel) {
			actionPerformedMntmDptDel(e);
		}if(e.getSource() == mntmDptAdd) {
			actionPerformedMntmDptAdd(e);
		}
	}
	
	protected void actionPerformedMntmDptAdd(ActionEvent e) {
		panel_Center.removeAll();
		panel_Center.add(pnDept);
		pnDept.btnAction.setText("추가");
		panel_Center.revalidate();
	}

	protected void actionPerformedMntmDptDel(ActionEvent e) {
		panel_Center.removeAll();
		panel_Center.add(pnDept);
		pnDept.btnAction.setText("삭제");
		panel_Center.revalidate();
	}
	
	protected void actionPerformedMntmDptUp(ActionEvent e) {
		panel_Center.removeAll();
		panel_Center.add(pnDept);
		pnDept.btnAction.setText("수정");
//		panel_Center.revalidate();
//		getContentPane().add(pnDeptBody);
//		pnDeptBody.btnAction.setText("수정");
	}
	protected void actionPerformedMntmSearch(ActionEvent e) {
		panel_Center.removeAll();
		panel_Center.add(pnDept);
		pnDept.btnAction.setText("검색");
//		panel_Center.revalidate();
//		getContentPane().add(pnDeptBody);
//		pnDeptBody.btnAction.setText("검색");
	}
	protected void actionPerformedMntmDptList(ActionEvent e) {
		panel_Center.removeAll();
		panel_Center.add(deptJtable);
		
//		pnDeptBody.add(deptJtable);
//		panel_Center.revalidate();
	}
	
	
}
